package com.wzdigit.wms.wms.controller.basic;

import com.wzdigit.framework.exception.RestStatusException;
import com.wzdigit.framework.model.response.ErrorEntity;
import com.wzdigit.wms.common.utils.ValidatorUtil;
import com.wzdigit.wms.basic.client.Pager;
import com.wzdigit.wms.basic.client.PagerInfo;
import com.wzdigit.wms.basic.client.request.basic.CreateUpdateListLocationAttrRequest;
import com.wzdigit.wms.basic.client.response.Result;
import com.wzdigit.wms.basic.client.response.basic.LocationAttrResponse;
import com.wzdigit.wms.wms.constant.WmsWareConstant;
import com.wzdigit.wms.wms.service.basic.LocationAttrService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

/**
 * 库位属性 前端控制器
 * @author yangdongjie
 * @LocationAttrController.java
 * @2020年12月31日下午5:56:27
 */
@RestController
@Api(tags = "库位属性")
@RequestMapping(value = WmsWareConstant.API_VERSION)
public class LocationAttrController {

    @Autowired
    private LocationAttrService locationAttrService;

    private static final String REQUEST_MODEL = "/location/attr";

    /**
     * 查询库位属性列表
     * @param <T>
     * @param locId
     * @param pager
     * @param servletRequest
     * @param servletResponse
     * @return
     */
    @ApiOperation(value = "查询库位属性列表",notes = "查询库位属性列表")
    @ApiResponses({ @ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class) })
    @GetMapping(value = REQUEST_MODEL + "/searchLocationAttr")
    public <T> PagerInfo<List<LocationAttrResponse>> searchLocationAttr(
    		@ApiParam(value = "库位ID", required = true) 
    		@RequestParam Integer locId, 
    		Pager<T> pager, 
    		HttpServletRequest servletRequest, 
            HttpServletResponse servletResponse) {
        try {
            return locationAttrService.searchLocationAttr(locId, pager);
        } catch (RestStatusException e) {
            e.printStackTrace();
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw e;
        }
    }
    
    
    /**
     * 批量新增/修改/删除 库位属性
     * @param <T>
     * @param dto
     * @param bindingResult
     * @param servletRequest
     * @param servletResponse
     * @return
     */
	@ApiOperation(value = "批量新增/修改/删除 库位属性",notes = "批量新增/修改/删除 库位属性")
    @ApiResponses({ @ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class) })
    @PostMapping(value = REQUEST_MODEL + "/createUpdateListLocationAttr")
    public <T> Result<T> createUpdateListLocationAttr(
    		@RequestBody @Valid CreateUpdateListLocationAttrRequest dto, 
    		BindingResult bindingResult, 
    		HttpServletRequest servletRequest, 
            HttpServletResponse servletResponse) {
        try {
        	ValidatorUtil.validator(bindingResult);
            return locationAttrService.createUpdateListLocationAttr(dto, servletRequest);
        } catch (RestStatusException e) {
            e.printStackTrace();
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw e;
        }
    }
    
    /**
     * 创建库位属性
     * @param dto
     * @param bindingResult
     * @param servletRequest
     * @param servletResponse
     * @return
     *//*
    @ApiOperation(value = "创建库位属性",notes = "创建库位属性")
    @ApiResponses({ @ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class) })
    @PostMapping(value = REQUEST_MODEL + "/createLocationAttr")
    public LocationAttrResponse createLocationAttr(
    		@RequestBody @Valid CreateLocationAttrRequest dto, 
    		BindingResult bindingResult, 
    		HttpServletRequest servletRequest, 
            HttpServletResponse servletResponse) {
        try {
	    	ValidatorUtil.validator(bindingResult);
            return locationAttrService.createLocationAttr(dto, servletRequest);
        } catch (RestStatusException e) {
            e.printStackTrace();
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw e;
        }
    }
    
    *//**
     * 修改库位属性
     * @param dto
     * @param bindingResult
     * @param servletRequest
     * @param servletResponse
     * @return
     *//*
    @ApiOperation(value = "修改库位属性",notes = "修改库位属性")
    @ApiResponses({ @ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class) })
    @PutMapping(value = REQUEST_MODEL + "/updateLocationAttr")
    public LocationAttrResponse updateLocationAttr(
    		@RequestBody @Valid UpdateLocationAttrRequest dto, 
    		BindingResult bindingResult, 
    		HttpServletRequest servletRequest, 
            HttpServletResponse servletResponse) {
        try {
	    	ValidatorUtil.validator(bindingResult);
            return locationAttrService.updateLocationAttr(dto, servletRequest);
        } catch (RestStatusException e) {
            e.printStackTrace();
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw e;
        }
    }
    
    *//**
     * 删除库位属性
     * @param locationAttrId
     * @param servletRequest
     * @param servletResponse
     * @return
     *//*
    @ApiOperation(value = "删除库位属性",notes = "删除库位属性")
    @ApiResponses({ @ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class) })
    @DeleteMapping(value = REQUEST_MODEL + "/deleteLocationAttr")
    public <T> Result<T> deleteLocationAttr(
    		@ApiParam(value = "库位属性ID", required = true) 
    		@RequestParam Integer locationAttrId, 
    		HttpServletRequest servletRequest, 
            HttpServletResponse servletResponse) {
        try {
            return locationAttrService.deleteLocationAttr(locationAttrId);
        } catch (RestStatusException e) {
            e.printStackTrace();
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw e;
        }
    }*/
}
